package pl.smath.expression;

public class ExponentiationTerm extends Term{

	private Term base;
	private Term exponent;
	
	/**
	 * Construktor
	 * @param text
	 */
	public ExponentiationTerm(Term base, Term exponent) {
		super("^");
		
		this.base = base;
		this.exponent = exponent;
		
	}
	
	/**
	 * @return tekst wyrażenia
	 */
	public Term copy(){
		Term term = new ExponentiationTerm(base.copy(), exponent.copy());
		
		term.setNegative(isNegative());
		return term;
	}

	
	
	/**
	 * Pobranie podstawy
	 */
	public Term getBase(){
		return base;
	}

	
	/**
	 * Pobranie wykladnika
	 */
	public Term getExponent(){
		return exponent;
	}
	
	
	/**
	 * Sprawdzenie czy 2 wyrazenia sa sobie równowazne.
	 * Czyli czy mozna postawic miedzy nimi znak = (w sensie matematycznym)
	 */
	public boolean isTheSame(Term term){
		
		if(term instanceof ExponentiationTerm){
			ExponentiationTerm et = (ExponentiationTerm)term;
			return base.isTheSame(et.getBase()) && exponent.isTheSame(et.getExponent());
		}
		
		return false;
	}
	
	
	/**
	 * Zamien na string
	 */
	public String toString(){
		String output = "";
		
		if(isNegative())
			output = "-";
		
		if(base instanceof MultiTerm)
			output += "(" + base.toString() + ")";
		else
			output += base.toString();
		
		output += "^" + exponent.toString();
		return output;

	}

}
